<%--
  Created by IntelliJ IDEA.
  User: YuanDali
  Date: 2020/7/20
  Time: 20:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>贾楼影院后台管理系统</title>
    <link rel="stylesheet" type="text/css" href="../../back/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="../../back/css/admin.css"/>
    <style>
        .setStartTimeInputBlock {
            display: inline-block;
        }
        .setStartTimeInputnone {
            display: none;
        }
        .setEndTimeInputBlock {
            display: inline-block;
        }
        .setEndTimeInputnone {
            display: none;
        }
    </style>
</head>
<body>
<div class="main-layout" id='main-layout'>
    <!--侧边栏-->
    <div class="main-layout-side">
        <div class="m-logo">
        </div>
        <ul class="layui-nav layui-nav-tree" lay-filter="leftNav">
            <li class="layui-nav-item">
                <a href="movie_back.jsp" data-url="article-list.html"><i class="iconfont">&#xe608;</i>电影管理</a>
            </li>
            <li class="layui-nav-item">
                <a href="movie_arrange_manage.jsp"><i class="iconfont">&#xe604;</i>场次管理</a>
            </li>
            <li class="layui-nav-item">
                <a href="feedback-list.jsp"><i class="iconfont">&#xe60c;</i>评论管理</a>
            </li>
            <li class="layui-nav-item">
                <a href="order_list.jsp"><i class="iconfont">&#xe600;</i>订单管理</a>
            </li>
            <li class="layui-nav-item">
                <a href="charts.jsp"><i class="iconfont">&#xe60d;</i>票房统计</a>
            </li>
        </ul>
    </div>
    <!--右侧内容-->
    <div class="main-layout-container">
        <!--头部-->
        <div class="main-layout-header">
            <div class="menu-btn" id="hideBtn">
                <a href="javascript:;">
                    <span class="iconfont">&#xe60e;</span>
                </a>
            </div>
            <ul class="layui-nav" lay-filter="rightNav">
                <li class="layui-nav-item"><a href="${pageContext.request.contextPath}/admin/outLogin"">退出</a></li>
            </ul>
        </div>
        <!--主体内容-->
        <div class="main-layout-body">
            <!--tab 切换-->
            <div class="layui-tab layui-tab-brief main-layout-tab" lay-filter="tab" lay-allowClose="true">
                <ul class="layui-tab-title">
                    <li class="layui-this welcome">场次管理</li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show" style="background: #f5f5f5;">
                        <div class="wrap-container clearfix">
                            <div class="column-content-detail">
                                <%--<form class="layui-form" action="#">--%>
                                    <div class="layui-form-item">
                                        <div class="layui-inline tool-btn">
                                            <button class="layui-btn layui-btn-small layui-btn-normal addBtn" data-url="article-add.html"><i class="layui-icon">&#xe654;</i></button>
                                            <%--<button class="layui-btn layui-btn-small layui-btn-danger delBtn"  data-url="article-add.html"><i class="layui-icon">&#xe640;</i></button>--%>
                                            <button class="layui-btn layui-btn-small layui-btn-warm listOrderBtn hidden-xs" data-url="article-add.html"><i class="iconfont">&#xe656;</i></button>
                                        </div>
                                        <%--<div class="layui-inline">
                                            <input type="text" name="title" required lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
                                        </div>--%>
                                        <div class="layui-inline" id="hallNameSelect">
                                            <%--<select name="states" lay-filter="status">
                                                <option value="">全部</option>

                                            </select>--%>
                                        </div>
                                        <input class="layui-input" type="text" placeholder="请输入影名" id="movieNameSelect" value="" style="width: 213px;display: inline-block">
                                        <input class="layui-input" type="date"  id="selectDate" style="width: 213px;display: inline-block">
                                        <button class="layui-btn layui-btn-normal" lay-submit="search" id="selectButton">搜索</button>
                                    </div>
                                <%--</form>--%>
                                <div class="layui-form" id="table-list">
                                    <table class="layui-table" lay-even lay-skin="nob">
                                        <colgroup>
                                            <col class="hidden-xs" width="50">
                                            <col class="hidden-xs" width="100">
                                            <col class="hidden-xs" width="150">
                                            <col class="hidden-xs" width="150">
                                            <col width="80">
                                            <col width="150">
                                        </colgroup>
                                        <thead>
                                        <tr>
                                            <th class="hidden-xs" style="width: 100px">电影名称</th>
                                            <th class="hidden-xs">播放厅</th>
                                            <%--<th>名称</th>--%>
                                            <th class="hidden-xs" style="width: 150px">开始时间</th>
                                            <th class="hidden-xs">结束时间</th>
                                            <th>状态</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        <tbody id="tableBody">
                                        <%--<tr >--%>
                                            <%--<td>
                                                <input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose">
                                            </td>
                                            <td class="hidden-xs" style="width: 213px;">
                                                <input class="layui-input" type="text" value="" placeholder="请输入影名" id="movieNameInput" style="width: 213px;display: inline-block;border: 1px;">
                                            </td>
                                            <td class="hidden-xs" style="width: 103px;">
                                                <input class="layui-input" type="text" value="" placeholder="请输入厅名" id="hallNameInput" style="width: 100px;display: inline-block;border: 1px;">
                                            </td>
                                            &lt;%&ndash;<td>玩具</td>&ndash;%&gt;
                                            <td class="hidden-xs">
                                                <label id="startTimeLabel">2020-07-28 12:30</label>
                                                <input type="datetime-local" name="startTime" id="startTime" value="" class="layui-input" style="width: 180px;display:none">
                                            </td>
                                            <td class="hidden-xs">
                                                <input class="layui-input" type="text"  id="endTime" style="width: 180px;display: inline-block;border: 1px;" readonly="readonly">
                                            </td>
                                            <td><button class="layui-btn layui-btn-mini layui-btn-normal">正常</button></td>
                                            <td>
                                                <div class="layui-inline">
                                                    <button class="layui-btn layui-btn-small layui-btn-normal go-btn" data-id="1" data-url="article-detail.html"><i class="layui-icon">&#xe642;</i></button>
                                                    <button class="layui-btn layui-btn-small layui-btn-danger del-btn" data-id="1" data-url="article-detail.html"><i class="layui-icon">&#xe640;</i></button>
                                                </div>
                                            </td>--%>
                                        <%--</tr>--%>

                                        </tbody>
                                    </table>
                                    <div class="page-wrap">
                                        <ul class="pagination">
                                            <%--<li class="disabled">
                                                <a href="#">«</a>
                                            </li>
                                            <li class="active">
                                                <a href="#">1</a>
                                            </li>
                                            <li>
                                                <a href="#">»</a>
                                            </li>--%>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--遮罩-->
    <div class="main-mask">

    </div>
</div>
<script src="../../back/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="../../back/js/common.js" type="text/javascript" charset="utf-8"></script>
<script src="../../back/js/main.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="../back/js/jquery.min.js"></script>
</body>
<script>
    $(document).ready(function () {
        //进页面后加载播放厅
        //从session中获取管理员id
        var adminId = "${sessionScope.adminId}";
        /*var adminId = "101";*/
        //发送ajax请求获取播放厅名
        $.ajax({
            async:true,
            url:"${pageContext.request.contextPath}/movieArrange/getAllHallNameByCinema",
            data:{
                adminId:adminId
            },
            dataType:"json",
            type:"get",
            success:function (result) {
                console.log(result);
                var content = "";
                content = "<select class=\"layui-input\" name=\"states\" lay-filter=\"status\" id='hallName'>\n" +
                    "        <option value=\"\">全部</option>";
                for (var i=0;i<result.length;i++){
                    content +=" <option value=\"010\">"+result[i]+"</option>";
                }
                content += "</select>";
                //成功后对下拉框进行填充
                $("#hallNameSelect").append(content);
                sendAjax(1);
            },
            error:function(){
                alert("ajax请求失败");
            }
        });
    });//入口函数结束

    //发送ajax方法
    function sendAjax(pageNum) {
        //从session中获取管理员id
        var adminId = "${sessionScope.adminId}";
        var adminId = "101";
        //获取播放厅下拉框中的值
        var hallName = $("#hallName option:selected").text();
        //获取电影名输入框中的值
        var movieName = $("#movieNameSelect").val();
        //获取日期框中的值
        var startTime = $("#selectDate").val();
         // alert("===="+startDate);
        //发送ajax
        $.ajax({
            async:true,
            url:"${pageContext.request.contextPath}/movieArrange/movieArrangeByCinema",
            data:{
                adminId:adminId,
                hallName:hallName,
                movieName:movieName,
                startTime:startTime,
                pageNum:pageNum
            },
            dataType:"json",
            type:"get",
            success:function (result) {
                console.log(result);
                //拼接表格
                var content ="";
                for (var i=0;i<result.list.length;i++){
                    //获取开始时间
                    var startTime = new Date(result.list[i].startTime);
                    var endTime = new Date(result.list[i].endTime);
                    var startDay = startTime.getDate();
                    var startMonth = (startTime.getMonth()+1 < 10 ? '0'+(startTime.getMonth()+1) : startTime.getMonth()+1);
                    var startHours = startTime.getHours();
                    var startMinutes = startTime.getMinutes();
                    var endDay = endTime.getDate();
                    var endMonth = (endTime.getMonth()+1 < 10 ? '0'+(endTime.getMonth()+1) : endTime.getMonth()+1);
                    var endMinutes = endTime.getMinutes();
                    var endHours = endTime.getHours();
                    startTime = startMonth+"月"+startDay+"号"+startHours+"点"+startMinutes+"分";
                    endTime = endMonth+"月"+endDay+"号"+endHours+"点"+endMinutes+"分";
                    content+="<tr>"+
                        "                                            <td class=\"hidden-xs\" style=\"width: 213px;\">\n" +
                        "                                                <input class=\"layui-input movieNameInput\" type=\"text\" value=\""+result.list[i].movieName+"\" placeholder=\"请输入影名\" readonly='readonly' style=\"width: 213px;display: inline-block;border: 1px;\">\n" +
                        "                                            </td>\n" +
                        "                                            <td class=\"hidden-xs\" style=\"width: 103px;\">\n" +
                        "                                                <input class=\"layui-input hallNameInput\" type=\"text\" readonly='readonle' value='"+result.list[i].hallName+"' placeholder=\"请输入厅名\"  style=\"width: 100px;display: inline-block;border: 1px;\">\n" +
                        "                                            </td>\n" +
                        "                                            <td class=\"hidden-xs\">\n" +
                        "                                                <label onclick='setStartTime(this)' class='setStartTimeLabel'>"+startTime+"</label>\n" +
                        "                                                <input type=\"datetime-local\" name=\"startTime\"  value=\"\" class=\"layui-input startTime setStartTimeInputnone\" style=\"width: 180px;\">\n" +
                        "                                            </td>\n" +
                        "                                            <td class=\"hidden-xs\">\n" +
                        "                                                <label onclick='setEndTime(this)' class='setEndTimeLabel'>"+endTime+"</label>\n" +
                        "                                                <input type=\"datetime-local\" name=\"endTime\"  value=\"\" class=\"layui-input endTime setEndTimeInputnone\" style=\"width: 180px;\">\n"+
                        "                                            </td>\n" +
                        "                                            <td><button class=\"layui-btn layui-btn-mini layui-btn-normal\">"+result.list[i].showStatus+"</button></td>\n" +
                        "                                            <td>\n" +
                        "                                                <div class=\"layui-inline\">\n" +
                        "                                                    <button class=\"layui-btn layui-btn-small layui-btn-normal go-btn\" onclick='setMovieManage(this,"+result.list[i].manageId+")' data-id=\"1\" data-url=\"article-detail.html\"><i class=\"layui-icon\">&#xe642;</i></button>\n" +
                        "                                                    <button class=\"layui-btn layui-btn-small layui-btn-danger del-btn\" data-id=\"1\" data-url=\"article-detail.html\"><i class=\"layui-icon\">&#xe640;</i></button>\n" +
                        "                                                </div>\n" +
                        "                                            </td>"+
                        "</tr>";
                }
                //追加
                $("#tableBody").append(content);
                pageinfomessage(result.prePage,result.pages,result.nextPage);
            },
            error:function(){
                alert("ajax请求失败");
            }
        });
    }

    //分页方法

    function pageinfomessage(prePage,pages,nextPage){
        $(".pagination").empty();
        //拼接页码
        var contentPage = "<li class=\"disabled\">\n" +
            "                     <a href=\"#\" data-tip='"+prePage+"' id='prePage'>«</a>\n" +
            "               </li>";
        for (var i= 1;i<=pages;i++){
            contentPage +=
                "                                            <li class=\"active\">\n" +
                "                                                <a href=\"#\" onclick='pageInfo(this,"+i+")'>"+i+"</a>\n" +
                "                                            </li>";
        }
        contentPage +="<li>\n" +
            "            <a href=\"#\" data-nextpage='"+nextPage+"' data-pages='"+pages+"' id='nextPage'>»</a>\n" +
            "         </li>";
        //将其追加到响应位置
        $(".pagination").append(contentPage);
    }

    //对搜索按钮做点击事件
    $("#selectButton").click(function () {
        //清空表格体
        $("#tableBody").empty();
        sendAjax(1);
    });

    //开始时间的点击事件
    function setStartTime(startTime){
        $(".setStartTimeLabel").removeClass("setStartTimeInputnone");
        $(".startTime").addClass("setStartTimeInputnone");
        $(startTime).addClass("setStartTimeInputnone");
        //对可编辑的的input释放css
        $(startTime).next().removeClass("setStartTimeInputnone");
        $(startTime).next().addClass("setStartTimeInputBlock");
    }
    //结束时间的点击事件
    function setEndTime(endTime){
        $(".setEndTimeLabel").removeClass("setEndTimeInputnone");
        $(".endTime").addClass("setEndTimeInputnone");
        $(endTime).addClass("setEndTimeInputnone");
        //对可编辑的的input释放css
        $(endTime).next().removeClass("setEndTimeInputnone");
        $(endTime).next().addClass("setEndTimeInputBlock");
    }

    function setMovieManage(thisObject,manageId) {
       var tr = $(thisObject).parents("tr");
        var newStartTime = tr.find(".setStartTimeInputBlock").val();
        var newEndTime = tr.find(".setEndTimeInputBlock").val();
        alert("==="+newStartTime+"---"+manageId+"==="+newEndTime);
        if (newStartTime == undefined || newEndTime ==undefined){
            alert("===请设置时间=====");
        }else{
            //发送ajax
            $.ajax({
                async:true,
                url:"${pageContext.request.contextPath}/movieArrange/updateMovieManage",
                data:{
                    manageId:manageId,
                    startTime:newStartTime,
                    endTime:newEndTime
                },
                dataType:"json",
                type:"get",
                success:function (result) {
                    console.log(result);
                },
                error:function(){
                    alert("ajax请求失败");
                }
            });
        }


    }

    //对上一页做点击事件
    $(document).on("click","#prePage",function () {
        //如果上一页页码为0，则设置上一页不可用
        var pageNum = $("#prePage").attr("data-tip");
        if (pageNum==0){
            //设置上一页不可用
            $(this).css("disabled","disabled");
        } else{
            //清空原有的分页信息
            $(".pagination").empty();
            //清空原有的电影信息
            $("#tableBody").empty();
            sendAjax(pageNum);
        }
    });

    //对下一页做点击事件
    $(document).on("click","#nextPage",function () {
        var pageNum = $("#nextPage").attr("data-nextpage");
        var pages = $("#nextPage").attr("data-pages");
        if (pageNum==pages){
            //设置下一页不可用
            $(this).css("disabled","disabled");
        } else{
            //清空原有的分页信息
            $(".pagination").empty();
            //清空原有的电影信息
            $("#tableBody").empty();
            sendAjax(pageNum);
        }
    });

    function pageInfo(thisObject,pageNum) {
        //设置自己的背景颜色
        $(thisObject).css("background","blue");
        //清空原有的分页信息
        $(".pagination").empty();
        //清空原有的电影信息
        $("#tableBody").empty();
        sendAjax(pageNum);
    }
</script>
</html>


